import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:speed_random/app_styles.dart';

import 'package:speed_random/widgets/not_data.dart';
import 'package:speed_random/widgets/zdy_confirm.dart';

import 'logic.dart';
import 'state.dart';

class RandListListPage extends StatelessWidget {
  RandListListPage({Key? key}) : super(key: key);

  final RandListListLogic logic = Get.put(RandListListLogic());
  final RandListListState state = Get.find<RandListListLogic>().state;




// ... 其他代码保持不变 ...


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title:  Obx(()=>Text(state.title.value+'(${state.historyNumbers.value.length})')),
        backgroundColor: AppStyles.colorAppBarbg,
        actions: [
          IconButton(
            icon: const Icon(Icons.offline_pin_rounded),
            onPressed: () {
             logic.SaveList();
             EasyLoading.showSuccess('成功'.tr);
             // 返回上一页。
             Navigator.of(context).pop();
            },
          ),
        ],
      ),
      body:Column(
        children: [

          // 这里有一个输入框，后面一个加号按钮。点击加号按钮后，将输入框中的内容添加到列表中。输入框需要添加成卡片形式。
          Card(
            margin: const EdgeInsets.all(10),
            elevation: 2,
            child: Padding(
              padding: const EdgeInsets.only(left: 10, right: 10, top: 12, bottom: 12),
              child: Row(
                children: [
                  Expanded(
                    child: TextField(
                      decoration:  InputDecoration(
                        hintText: '请输入内容'.tr,
                        border: InputBorder.none,
                      ),
                      controller: logic.textController,
                    ),
                  ),
                  IconButton(
                    icon: const Icon(Icons.add_circle_sharp),
                    onPressed: () {
                      if (logic.textController.text.isNotEmpty) {
                        logic.addItem(logic.textController.text);
                        logic.textController.clear();
                      }else{
                        EasyLoading.showError('请输入内容'.tr);
                      }
                    },
                  ),
                ],
              ),
            ),
          ),
          Expanded(child: Obx(() =>state.historyNumbers.value.length==0? notData(): ListView.builder(
              itemCount: state.historyNumbers.value.length,
              padding: const EdgeInsets.all(5),
              itemBuilder: (context, index) {
                final indext = state.historyNumbers.value.length - 1 - index;
                final numbers = state.historyNumbers.value[indext];

              // ... 其他代码保持不变 ...

return Card(
    elevation: 3,
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.circular(12),
      side: BorderSide(
        color: Colors.grey.withOpacity(0.3),
        width: 1,
      ),
    ),
    child: Padding(
      padding: const EdgeInsets.all(12),
      child: Row(
        children: [
          Expanded(
            child: Text(
              numbers.toString(),
              style: TextStyle(fontSize: 16),
            ),
          ),
          IconButton(
            icon: Icon(Icons.remove_circle, color: Colors.red),
            onPressed: () {
              logic.removeItem(indext);
             /* zdyConfirm(context: context, title: "提示".tr, content: "是否确定删除".tr, onOKPressed: (){
                logic.removeItem(indext);
              }, onCancelPressed: (){

              });*/

            },
          ),
        ],
      ),
    ),
);

// ... 其他代码保持不变 ...




              })
          ))
        ],
      )
    );
  }
}
